package com.area.cth.service.impl;

import com.area.cth.mapper.CollectMapper;
import com.area.cth.pojo.Collect;
import com.area.cth.service.CollectService;
import com.area.cth.utils.ThreadLocalUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service
public class CollectServiceImpl implements CollectService {
    @Autowired
    private CollectMapper lm;

    @Override
    public void addLike(Integer gId) {
        Map<String,Object> map = ThreadLocalUtil.get();
        Integer uId = (Integer) map.get("id");
        lm.addLike(gId,uId);
    }

    @Override
    public Collect likeIf(Integer gId) {
        Map<String,Object> map = ThreadLocalUtil.get();
        Integer uId = (Integer) map.get("id");
        return lm.likeIf(gId,uId);
    }

    @Override
    public void deleteLike(Integer lId) {
        lm.deleteLike(lId);
    }

    @Override
    public List<Collect> getMyCollect() {
        Map<String,Object> map = ThreadLocalUtil.get();
        Integer uid = (Integer) map.get("id");
        return lm.getMyCollect(uid);
    }

    @Override
    public void deleteLikeByGoodsId(Integer gId) {
        Map<String,Object> map = ThreadLocalUtil.get();
        Integer uId = (Integer) map.get("id");
        lm.deleteLikeByGoodsId(gId,uId);
    }
}
